package com.liuyun.crypt;

import org.mindrot.jbcrypt.BCrypt;

/**
 * <p>
 * Copyright: (C), 2020/12/27 21:41
 * <p>
 * <p>
 * Company Information & Data Security Solutions Co., Ltd.
 *
 * @author LiuYun liujw@idss-cn.com
 * @version 1.0
 */
public class BCryptDemo {

    public static void main(String[] args) {
        String password = "12345";
        String salt = BCrypt.gensalt();
        String hashed = BCrypt.hashpw(password, salt);
        assert "$2a$10$WXDv7jlFaui0Sf32PGrFI.M18X1j1FO6hZqpGMXib3qHPoA9dHpRu".equals(BCrypt.hashpw(password, "$2a$10$WXDv7jlFaui0Sf32PGrFI."));
        /**
         * BCrypt.gensalt()的结果：$2a$10$WXDv7jlFaui0Sf32PGrFI.
         * 该方法生成的盐值，每次都不一样，故下面的hash结果也不一样
         * BCrypt.hashpw的结果：$2a$10$WXDv7jlFaui0Sf32PGrFI.M18X1j1FO6hZqpGMXib3qHPoA9dHpRu
         *
         */
        System.out.println(salt);
        System.out.println(hashed);
        System.out.println(BCrypt.checkpw(password, hashed));
        System.out.println(BCrypt.checkpw(password, "$2a$10$WXDv7jlFaui0Sf32PGrFI.M18X1j1FO6hZqpGMXib3qHPoA9dHpRu"));
    }
}
